home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / sun / lib2 / errors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-15  |  3.1 KB  |  142 lines

  1. /*
  2. %    ERRORS . C
  3. %
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5.  
  6. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  7. Permission is granted to reproduce this software for non-commercial
  8. purposes provided that this notice is left intact.
  9.  
  10. It is acknowledged that the U.S. Government has rights to this software
  11. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  12. and the University of California.
  13.  
  14. This software is provided as a professional and academic contribution
  15. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  16. with no warranties of any kind whatsoever, no support, no promise of
  17. updates, or printed documentation. By using this software, you
  18. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  19. University of California shall have no liability with respect to the
  20. infringement of other copyrights by any part of this software.
  21.  
  22. For further information about this notice, contact William Johnston,
  23. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  24. (wejohnston@lbl.gov)
  25.  
  26. For further information about this software, contact:
  27.     Jin Guojun
  28.     Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  29.     g_jin@lbl.gov
  30.  
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32. %
  33. %    Error handler -- for all machines.
  34. %
  35. % AUTHOR:    Jin Guojun - LBL    10/1/90
  36. */
  37.  
  38. #include <errno.h>
  39. #include "header.def"
  40. #include "imagedef.h"
  41.  
  42. extern    int    sys_nerr;
  43. extern    char    *sys_errlist[];
  44.  
  45. char    *Mversion, *io_test_msg[] = {"stdin", "stdout", "stderr", "aux", "?"};
  46.  
  47. #ifndef    HIPS2_HF
  48. char    *Progname;
  49. int    hipserrlev, hipserrprt;
  50. #endif
  51.  
  52. #define    HaveMVersion    Mversion ? Mversion : "NoVer"
  53. #define    Error_Body(virtual)    \
  54.     message("%s [%s] : ", Progname, HaveMVersion);    \
  55.     vfprintf(stderr, (char*)vfmt, virtual);    \
  56.     error_mesg();
  57. #define    HowFatal()    if (fatal > 0)    exit(fatal);    return    ~fatal;
  58.  
  59. void
  60. error_mesg()
  61. {
  62. if (errno>0 && errno<sys_nerr)
  63.     message("; Error<%d> %s", errno, sys_errlist[errno]);
  64. mesg("\n");    fflush(stderr);
  65. }
  66.  
  67. #if    !defined TC_Need
  68.  
  69. #include <varargs.h>
  70.  
  71. #ifdef    SHOW_WARNINGS
  72. VType    /*    system error function for va_list handling machines.    */
  73. #endif
  74.  
  75. #ifndef    NO_V_LIST
  76. #ifdef    MIPS
  77. syserr(char* vfmt, ...)
  78. #else
  79. syserr(vfmt, va_alist)
  80. va_list    va_alist;
  81. #endif
  82. {
  83. va_list    ap;
  84.  
  85. va_start(ap);
  86. Error_Body(ap);
  87. exit(errno);
  88. }
  89.  
  90. #ifdef    MIPS
  91. prgmerr(bool fatal, char* vfmt, ...)
  92. #else
  93. prgmerr(fatal, vfmt, va_alist)
  94. va_list    va_alist;
  95. #endif
  96. {
  97. va_list    ap;
  98.  
  99. va_start(ap);
  100. Error_Body(ap);
  101. HowFatal();
  102. }
  103.  
  104. #else    /* some stupid C compiler, can't handle virtual lists easier    */
  105.  
  106. syserr(s, a1, a2, a3, a4, a5, a6)
  107. char *s;
  108. {
  109. message("%s [%s] : ", Progname, HaveMVersion);
  110. message(s, a1, a2, a3, a4, a5, a6);
  111. error_mesg();
  112. exit(errno);
  113. }
  114.  
  115. prgmerr(fatal, fmt, a1, a2, a3, a4)
  116. char    *fmt;
  117. {
  118. message("%s [%s] : ", Progname, HaveMVersion);
  119. message(fmt, a1, a2, a3, a4);
  120. error_mesg();
  121. HowFatal();
  122. }
  123. #endif    V_LIST
  124.  
  125. #else    FOR TURBO_C
  126. #include <stdarg.h>
  127.  
  128. syserr(char* vfmt, ...)
  129. {
  130. Error_Body(...);
  131. exit(errno);
  132. }
  133.  
  134. prgmerr(bool fatal, char* vfmt, ...)
  135. {
  136. message("%s [%s] : %s : ", Progname, HaveMVersion, strerror(errno));
  137. vfprintf(stderr, vfmt, ...);
  138. HowFatal();
  139. }
  140.  
  141. #endif    TC_Need
  142.